<?php

/**
 * 编写：祝踏岚
 * 用于对收款账号的操作
 */

namespace app\manage\model;

use think\Model;

class NftModel extends Model{
	//表名
	protected $table = 'ly_nft';
	/**
	 * 开关
	 */
	public function onOff(){
		if(!request()->isAjax()) return '非法提交';

		$param = input('post.');
		if(!$param) return '提交失败';

		//提取信息备用
		$bankInfo = $this->where('id',$param['id'])->find();

		$res = $this->where('id',$param['id'])->setField($param['field'],$param['val']);

		switch ($param['field']) {
			case 'status':
				$fieldName = '状态';
				break;

		}
		if($param['val']==1){
			$fieldState = '开启';
		}else{
			$fieldState = '关闭';
		}
		//添加操作日志
		model('Actionlog')->actionLog(session('manage_username'),'将nft:'.$bankInfo['name'].'的'.$fieldName.$fieldState,1);

		return 1;
	}
	/**
	 * 删除nft
	 */
	public function nftDel(){
		if(!request()->isAjax()) return '非法提交';

		$param = input('post.');
		if(!$param) return '提交失败';

		//提取信息备用
		$bankInfo = $this->where('id',$param['id'])->find();

		$delRes = $this->where('id',$param['id'])->update(['status'=>-1]);
		if(!$delRes) return '删除失败';

		//添加操作日志
		model('Actionlog')->actionLog(session('manage_username'),'删除nft：'.$bankInfo['name'],1);

		return 1;
	}
	/**
	 * nft审核
	 */
	public function nftCheck(){
		$param = input('post.');
		if(!$param) return '提交失败';

		$controlAuditTime = cache('CA_controlAuditTime'.session('manage_userid')) ? cache('CA_controlAuditTime'.session('manage_userid')) : time()-2;
		if(time() - $controlAuditTime < 2){
			return ' 2 秒内不能重复提交';
		}
		cache('CA_controlAuditTime'.session('manage_userid'), time(), 10);

		$id = $param['id'];

		//获取订单信息
		$where[] = array('id','=',$id);
//		$where[] = array('status','=',2);
		$orderInfo = $this->where($where)->find();
		if (!$orderInfo) return 'NFT不存在';
		$orderInfo = $orderInfo->toArray();
        unset($param['id']);
		$res = $this->where('id',$id)->update($param);
		if(!$res) return '操作失败1';

        if (isset($param['status'])){
            switch ($param['status']) {
                case 3:
                    //添加操作日志
                    model('Actionlog')->actionLog(session('manage_username'),'审核发布者NFT:'.$orderInfo['name'].'。处理状态：审核未通过',1);
                    break;

                case 1:
                    //添加操作日志
                    model('Actionlog')->actionLog(session('manage_username'),'审核发布者NFT:'.$orderInfo['name'].'。处理状态：审核通过',1);
                    break;
            }
        }

		return 1;
	}
}
